package com.lhdx.practical.bean;

import com.lhdx.practical.excelBean.ExcelStudent;
import com.lhdx.practical.excelBean.ExcelTeacher;
import com.lhdx.practical.utils.IDGenerator;
import com.lhdx.practical.utils.Md5Utils;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * 用户实体
 */
@Entity
@Table(name="person")
public class Person {
    @Id
    private long id;

    private String username;
    /**
     * 性别 0男 1女
     */
    private int sex;
    /**
     * 学号
     */
    private String userno;

    private String realname;

    private String password;
    /**
     * 用户类型 0管理员 1老师 2学生
     */
    private int type;
    /**
     * 简介
     */
    private String profile;
    /**
     * 头像
     */
    private String imgface;
    /**
     * 班级ID
     */
    private long departid;
    /**
     * 班级名称
     */
    private String departname;
    /**
     * 年级ID
     */
    private long gradeid;
    /**
     * 年级名称
     */
    private String gradename;

    private long logintime = 0;
    /**
     * 是否加入小组 0 未加入 1 创始人 2 成员
     */
    private int isjoin = 0;
    /**
     * 小组ID
     */
    private long groupid = 0;
    /**
     * 小组名称
     */
    private String groupname;
    /**
     * 加入小组时间
     */
    private long jointime = 0;

    public Person(){}

    public Person(ExcelStudent student,Depart depart,Depart grade,int type){
        this.id = IDGenerator.getID();
        this.username = student.getUsername();
        this.password = Md5Utils.md5(student.getPassword());
        this.realname = student.getRealname();
        this.userno = student.getUserno();
        this.profile = student.getProfile();
        this.departid = depart.getId();
        this.departname = depart.getDepartname();
        this.gradeid = grade.getId();
        this.gradename = grade.getDepartname();
        this.type = type;
        if(student.getSex().equals("男")){
            this.sex = 0;
        }else{
            this.sex = 1;
        }
    }

    public Person(ExcelTeacher teacher, int type){
        this.id = IDGenerator.getID();
        this.username = teacher.getUsername();
        this.password = Md5Utils.md5(teacher.getPassword());
        this.realname = teacher.getRealname();
        this.profile = teacher.getProfile();
        this.type = type;
        if(teacher.getSex().equals("男")){
            this.sex = 0;
        }else{
            this.sex = 1;
        }
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getRealname() {
        return realname;
    }

    public void setRealname(String realname) {
        this.realname = realname;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getProfile() {
        return profile;
    }

    public void setProfile(String profile) {
        this.profile = profile;
    }

    public String getImgface() {
        String face = "../../imgs/noimg.jpg";
        if(imgface != null && imgface.length() > 0){
            face = imgface;
        }
        return face;
    }

    public void setImgface(String imgface) {
        this.imgface = imgface;
    }

    public long getLogintime() {
        return logintime;
    }

    public void setLogintime(long logintime) {
        this.logintime = logintime;
    }

    public long getDepartid() {
        return departid;
    }

    public void setDepartid(long departid) {
        this.departid = departid;
    }

    public String getDepartname() {
        return departname;
    }

    public void setDepartname(String departname) {
        this.departname = departname;
    }

    public long getGradeid() {
        return gradeid;
    }

    public void setGradeid(long gradeid) {
        this.gradeid = gradeid;
    }

    public String getGradename() {
        return gradename;
    }

    public void setGradename(String gradename) {
        this.gradename = gradename;
    }

    public String getUserno() {
        return userno;
    }

    public void setUserno(String userno) {
        this.userno = userno;
    }

    public int getSex() {
        return sex;
    }

    public void setSex(int sex) {
        this.sex = sex;
    }

    public int getIsjoin() {
        return isjoin;
    }

    public void setIsjoin(int isjoin) {
        this.isjoin = isjoin;
    }

    public long getGroupid() {
        return groupid;
    }

    public void setGroupid(long groupid) {
        this.groupid = groupid;
    }

    public long getJointime() {
        return jointime;
    }

    public void setJointime(long jointime) {
        this.jointime = jointime;
    }

    public String getGroupname() {
        return groupname;
    }

    public void setGroupname(String groupname) {
        this.groupname = groupname;
    }
}
